<template>
  <van-nav-bar title="退货详情" left-arrow @click-left="back" />
  <section class="aui-flexView">
    <!-- 订单详细 -->
    <section class="aui-scrollView">
      <!-- 订单状态 -->
      <div class="aui-pay-change">
        <div class="aui-flex">
          <div class="aui-flex-box">
            <h3>{{ info.status_text }}</h3>
          </div>
          <div class="aui-pay-zfb">
            <img src="/assets/images/icon-zfb.png" alt="" />
          </div>
        </div>
      </div>

      <!-- 商家收货地址 -->
      <div class="aui-flex">
        <div style="font-size: 16px">收件地址：</div>
        <div class="aui-flex-box">
          <h3>
            {{ info.contact }} <em>{{ info.phone }}</em>
          </h3>
          <p>{{ info.adresss}}</p>
        </div>
      </div>

      <!-- 客户退货原因 -->
      <div class="aui-flex">
        <div>退货理由：</div>
        <div>{{ info.refundreason }}</div>
      </div>

      <!-- 客户寄件地址 退货单信息-->
      <div class="aui-flex">
        <div style="font-size: 16px">寄件地址：</div>
        <div class="aui-flex-box">
          <h3>
            {{ info.backinfo.contact }} <em>{{ info.backinfo.phone }}</em>
          </h3>
          <p>{{ info.backinfo.region_text }} {{ info.backinfo.address }}</p>
        </div>
      </div>

      <!-- 商家拒绝退货原因 -->
      <div class="aui-flex" v-if="info.examinereason">
        <div>商家协商：</div>
        <div>{{ info.examinereason }}</div>
      </div>

      <!-- 订单商品 -->
      <div class="aui-commodity-bg" style="background: transparent">
        <div
          style="margin-bottom: 10px; background: #f5f5f5"
          v-for="item in info.detail"
          :key="item.id"
        >
          <div class="aui-flex">
            <div class="aui-commodity-img">
              <img :src="item.product.thumb_text" />
            </div>
            <div class="aui-flex-box">
              <h4 class="van-ellipsis">商品名称：{{ item.product.name }}</h4>
              <p>商品单价：￥{{ item.price }}</p>
              <span class="aui-barter-time">七天退换</span>
            </div>
            <div>
              <h5>￥{{ item.total }}</h5>
              <p class="aui-sml-text">X{{ item.pronum }}</p>
            </div>
          </div>

          <div style="text-align: right">
            <van-button type="primary" size="mini" v-if="info.status == '3'"
              >评价
            </van-button>
          </div>
        </div>
      </div>

      <!-- 退货物流 -->
      <van-steps direction="vertical" :active="0">
        <van-step v-for="(item, index) in expresslist" :key="index">
          <h3>{{ item.status }}</h3>
          <p>{{ item.time }}</p>
        </van-step>
      </van-steps>
    </section>
  </section>
</template>
<script setup>
const { proxy } = getCurrentInstance();
const back = () => proxy.$router.push("/order/index");
let business = proxy.$cookies.get("business") ? proxy.$cookies.get("business") : {};
business = reactive(business);
let orderid = proxy.$route.query.hasOwnProperty("orderid")
  ? proxy.$route.query.orderid
  : 0;
orderid = ref(orderid);
const info = ref({
  address: {},
  detail: [],
  backinfo: {}
});
const expresslist = ref([]);
onBeforeMount(() => {
  getInfoData();
});
const getInfoData = async () => {
  let result = await proxy.$POST({
    url: "/order/info",
    params: {
      orderid: orderid.value,
      busid: business.id,
    },
  });
  if (result && result.code == 1) {
    info.value = result.data;
    getExpressData();
  }
};
const getExpressData = async () => {
  let result = await proxy.$POST({
    url: "/order/express",
    params: {
      backid: info.value.backinfo.id ?? 0,
      busid: business.id,
    },
  });
  if (result && result.code == 1) {
    // 数据倒转
    expresslist.value = result.data.reverse();
  }
};
</script>
<style>
@import url("/assets/css/info.css");
</style>
